﻿@{
    ViewData["Title"] = "Home Page";
}
@using Personalblog.Model.ViewModels
@using Personalblog.Model.Entitys
@model HomeViewModel

@section head{
    <link rel="stylesheet" href="~/lib/Home/HomeIndex.css"/>
    <script type="module" src="~/js/home.js"></script>
}

@await Html.PartialAsync("Widgets/BackTop", new BackToTopViewModel { IsShowText = false })
@if (Model.Notices.Any())
{
    @await Html.PartialAsync("Widgets/Notice", Model.Notices)
}
<div class="container">
    <div class="HomeImg mb-2">
        @await Html.PartialAsync("Widegets/HomeImg")
        <div class="HomeContent">
            <div class="mb-4" style="font-size:30px;float:left;">ZY 知识库</div>
            <div class="lead mb-2">
                <p class="text">{{poemSimple}}</p>
                @* <p>一言：{{hitokoto}}</p> *@
            </div>
            <div class="d-flex flex-sm-row Home-btn">
                <a class="btn btn-outline-secondary btn-lg px-4 mb-sm-0 box" role="button" asp-controller="About" asp-action="Index">了解更多</a>
                <div class="d-flex flex-row ms-sm-3" style="margin-left: 10px;">
                    <a class="btn btn-outline-secondary btn-lg px-4 me-2 box" asp-controller="Blog" asp-action="RandomPost">看文</a>
                    <a class="btn btn-outline-secondary btn-lg px-4 box" asp-controller="Photo" asp-action="RandomPhoto">看图</a>
                </div>
            </div>
        </div>
    </div>
    <div class="row">
        @{
            if (Model.HomePost.ViewCountMax!= null && Model.HomePost.CommentMax!= null && Model.HomePost.FirstPost != null && Model.HomePost.LastPost != null)
            {
                @await Html.PartialAsync("Widegets/HomePostTopCard", new FeaturedPostTopCardModel { HomePost = @Model.HomePost.ViewCountMax, Number = 1 })
                @await Html.PartialAsync("Widegets/HomePostTopCard", new FeaturedPostTopCardModel { HomePost = @Model.HomePost.CommentMax, Number = 2 })
                @await Html.PartialAsync("Widegets/HomePostTopCard", new FeaturedPostTopCardModel { HomePost = @Model.HomePost.FirstPost, Number = 3 })
                @await Html.PartialAsync("Widegets/HomePostTopCard", new FeaturedPostTopCardModel { HomePost = @Model.HomePost.LastPost, Number = 4 })
            }
        }
    </div>
</div>

<div class="container px-4 py-3" id="custom-cards">
    <h2 class="pb-2 border-bottom">Photography</h2>
    @if (Model.FeaturedPhotos.Any())
    {
        <div class="row row-cols-1 row-cols-lg-3 align-items-stretch g-4 py-5">
            @foreach (var photo in Model.FeaturedPhotos)
            {
                <div class="col  flip-container">
                    @await Html.PartialAsync("Widgets/PhotoCardSmall", photo)
                </div>
            }
        </div>
    }
    else
    {
        @await Html.PartialAsync("Widgets/PlaceholderCard", "推荐图片")
    }

</div>

<div class="container px-4 py-3" id="featured-3">
    <h2 class="pb-2 border-bottom">Blog Categories</h2>
    @if (Model.FeaturedCategories.Any())
    {
        <div class="row g-4 py-5 row-cols-1 row-cols-lg-3">
            @foreach (var fc in Model.FeaturedCategories)
            {
                @await Html.PartialAsync("Widgets/FeaturedCategoryCard", fc)
            }
        </div>
    }
    else
    {
        @await Html.PartialAsync("Widgets/PlaceholderCard", "推荐分类")
    }

</div>

<div class="container px-4 py-3">
    <h2 class="d-flex w-100 justify-content-between pb-2 mb-3 border-bottom">
        <div>Top Blog Posts</div>
        <div>文章推荐</div>
    </h2>
    @if (Model.TopPost != null)
    {
        @await Html.PartialAsync("Widegets/HomeTopPostCard", Model.TopPost)
    }
    else
    {
        @await Html.PartialAsync("Widgets/PlaceholderCard", "置顶博客")
    }


    @if (Model.FeaturedPosts.Any())
    {
        <div class="row mb-2" id="Home-list">
            @await Html.PartialAsync("Widgets/FeaturedPostCard", Model.FeaturedPosts)
        </div>
        <div class="row justify-content-center">
            <div class="col align-self-center text-center">
                <div class="ArcBtn" id="HomeBtn">
                    <button type="button" class="btn"
                            id="Home-more"
                            style="background-color:#33c2ff;color:white;box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);"
                            onclick="LoadHome()">
                        加载更多
                    </button>
                </div>
            </div>
        </div>
    }
    else
    {
        @await Html.PartialAsync("Widgets/PlaceholderCard", "推荐博客")
    }
</div>

<div class="container px-4 py-3">
    <h2 class="d-flex w-100 justify-content-between pb-2 mb-3 border-bottom">
        <div>All Posts</div>
        <div>所有文章</div>
    </h2>
    @if (Model.AllPosts.Item1.Any())
        {
            <div class="row mb-2" id="Home-list-All">
                @await Html.PartialAsync("Widegets/AllPostCard", Model.AllPosts)
            </div>
            <div class="row justify-content-center">
                <div class="col align-self-center text-center">
                    <div class="ArcBtn" id="HomeBtn">
                        <button type="button" class="btn"
                                id="Home-All"
                                style="background-color:#33c2ff;color:white;box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);"
                                onclick="LoadHomeAll()">
                            加载更多
                        </button>
                    </div>
                </div>
            </div>
        }
        else
        {
            @await Html.PartialAsync("Widgets/PlaceholderCard", "推荐博客")
        }
</div>

<div class="container px-4 py-3">
    <div class="d-flex justify-content-between mb-2 border-bottom">
        <h2>友情链接</h2>
        <a class="btn btn-link" asp-controller="LinkExchange" asp-action="Add">申请友链</a>
    </div>
    <div class="row">
        @if (Model.Links.Any())
        {
            @foreach (var link in Model.Links)
            {
                <div class="col-lg-3 col-md-6 col-sm-12">
                    @await Html.PartialAsync("Widgets/LinkExchange",
                               new ColorfulButtonViewModel { Name = link.Name, Url = link.Url, Description = link.Description, favicon = link.favicon })
                </div>
            }
        }
        else
        {
            @await Html.PartialAsync("Widgets/PlaceholderCard", "友情链接")
        }
    </div>
</div>
@* <div id="popupContainer" class="popup"> *@
@*     <span class="popup-span">求职 微信同号 24届应届生</span> *@
@*     <span class="close-btn" onclick="closePopup()"><i class="fa-solid fa-circle-xmark fa-2xl"></i></span> *@
@*     <iframe src="~/1.pdf#view=FitH,top" frameborder="0" seamless="seamless"></iframe> *@
@* </div> *@


@section bottom{
    <script src="~/lib/Home/HomeIndex.js"></script>
    @if (Model.TopPost != null)
    {
        <script>const CHART_VISIBLE = false</script>
    }
    else
    {
        <script>const CHART_VISIBLE = false</script>
    }
}